package com.lin.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 时间：2023/8/20
 */
@RestController
public class UserController {

    @GetMapping("/hello")
    public Authentication hello(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication;
    }

    @PreAuthorize("hasRole('product')")
    @GetMapping("/root")
    public Authentication rootIndex(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication;
    }

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/admin")
    public Authentication adminIndex(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return authentication;
    }
}
